package com.earthchen.spring.boot.service;

import com.earthchen.spring.boot.api.ProductRpc;
import com.earthchen.spring.boot.api.domain.ProductRpcReq;
import com.earthchen.spring.boot.domain.Product;
import com.earthchen.spring.boot.domain.enums.ProductStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 产品服务
 *
 * @author earthchen
 * @date 2018/8/11
 **/
@Service
public class ProductRpcService {

    private static Logger logger = LoggerFactory.getLogger(ProductRpcService.class);

    @Autowired
    private ProductRpc productRpc;

    /**
     * 查询全部产品
     *
     * @return
     */
    public List<Product> findAll() {
        ProductRpcReq req = new ProductRpcReq();
        List<String> status = new ArrayList<>();
        status.add(ProductStatus.IN_SELL.name());
        //Pageable pageable = new PageRequest(0, 1000, Sort.Direction.DESC, "rewardRate");
        req.setStatusList(status);
        req.setPage(0);
        req.setPageSize(1000);
        req.setDirection(Sort.Direction.DESC);
        req.setOrderBy("rewardRate");
        logger.info("rpc查询全部产品，请求{}", req);
        List<Product> result = productRpc.query(req);
        logger.info("rpc查询全部产品，结果{}", result);
        return result;
    }




}
